/*
* 订单列表
* */

/*
获取所有的订单信息
 */
//统一调用
getOrderList();
function getOrderList() {
    $.ajax({
        url:'/api/order/getList',
        type:'post',
        data:{},
        dataType:'json',
        success:function (data) {
            var html = "";
            $.each(data,function (index,item) {
                //遍历当前订单的详情，统计总金额
                var sum = 0;
                $.each(item.orderDetails,function (i,detail) {
                    sum += detail.price * detail.count
                });
                /*'+(item.status < 4 ? 'order-pay' : '')+'
                '+(item.status < 1 ? 'status-pay' : '')+'
                 '+['等待付款','等待发货','运送中','已收货','退货中','退货中'][item.status]+'
                 '+item.time+' | '+(item.address != null) ? item.address.contack : ''+' | 订单号：'+item.id+'| 在线支付（支付宝快捷支付）
                * */
                html += '<div class="order-box '+(item.status < 4 ? 'order-pay':'')+'">\n' +
                    '\t\t\t\t\t\t\t<div class="order-header">\n' +
                    '\t\t\t\t\t\t\t\t<div class="status '+(item.status < 4 ? 'status-pay':'')+' ">\n' +
                    ['等待付款','等待发货','运送中','已收货','退货中','退货中'][item.status] +
                    '\t\t\t\t\t\t\t\t</div>\n' +
                    '\t\t\t\t\t\t\t</div>\n' +
                    '\n' +
                    '\t\t\t\t\t\t\t<table class="detail">\n' +
                    '\t\t\t\t\t\t\t\t<thead>\n' +
                    '\t\t\t\t\t\t\t\t\t<tr>\n' +
                    '\t\t\t\t\t\t\t\t\t\t<th class="info">'+item.time+' | '+item.address.contact+' | 订单号：'+item.id+'| 在线支付（支付宝快捷支付）</th>\n' +
                    '\t\t\t\t\t\t\t\t\t\t<th class="money">应付金额： <span>'+sum+'</span> 元</th>\n' +
                    '\t\t\t\t\t\t\t\t\t</tr>\n' +
                    '\t\t\t\t\t\t\t\t</thead>\n' +
                    '\t\t\t\t\t\t\t\t<tbody>\n';
                  $.each(item.orderDetails,function (i,detail) {
                   html += '<tr>'+
                       '\t\t\t\t\t\t\t\t\t\t<td class="goods">\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t<div class="goods-box">\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t\t<div class="img">\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=""><img src="/upload/'+detail.goods.pictures[0].name+'" ></a>\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t\t</div>\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t\t<div class="goods-info">\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t\t\t<p class="name"><a href="/goods?id='+detail.goods.id+'">'+detail.goods.name+' '+detail.goods.version+' '+detail.goods.color+'</a></p>\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t\t\t<p class="price">'+detail.goods.price+'元 x 1</p>\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t\t</div>\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t</div>\n' +
                    '\t\t\t\t\t\t\t\t\t\t</td>\n' +
                    '\t\t\t\t\t\t\t\t\t\t<td class="actions">\n' +
                    (item.status == 0 ? '<a class="active" href="/user/order/pay?orderId='+detail.orderId+'&addressId='+item.addressId+'">立即付款</a>':'') +
                    '\t\t\t\t\t\t\t\t\t\t\t<a href="">订单详情</a>\n' +
                    '\t\t\t\t\t\t\t\t\t\t\t<a href="">联系客服</a>\n'
                  });
                  html +=  '\t\t\t\t\t\t\t\t</tbody>\n' +
                    '\t\t\t\t\t\t\t</table>\n' +
                    '\t\t\t\t\t\t</div>';
            });
            $(".order-list").html(html);
        },
        error:function () {

        }
    });
}